package thread;
/**
 * 静态方法锁
 */
public class SyncDemo3 {
    public static void main(String[] args) {
        Foo f1=new Foo();
        Foo f2=new Foo();
        new Thread(()->f1.doSome()).start();
        new Thread(()->f2.doSome()).start();
        new Thread(Foo::doSome).start();
    }
}
class Foo {
    public static  void doSome() {
        synchronized (Foo.class) {//静态方法的同步块中指定同步监视器对象仍然可以用类对象
            Thread t = Thread.currentThread();//获取运行该方法的线程
            System.out.println(t.getName() + "正在执行doSome方法");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(t.getName() + "执行doSome方法完毕");
        }
    }
}